package com.ssyc.gsk_teacher_appraisal.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

import com.ssyc.common.adapter.CommonAdapter;
import com.ssyc.common.adapter.ViewHolder;
import com.ssyc.common.view.ZzHorizontalProgressBar;
import com.ssyc.gsk_teacher_appraisal.R;
import com.ssyc.gsk_teacher_appraisal.bean.ReadLvInfo;

import java.util.List;


/**
 * 展示答案正确了的选项
 * Created by Administrator on 2018/9/10 0010.
 */

public class ReadShowAnswerAdapter extends CommonAdapter<ReadLvInfo> {
    private Context context;

    public ReadShowAnswerAdapter(Context context, List<ReadLvInfo> datas, int layoutId) {
        super(context, datas, layoutId);
        this.context = context;
    }

    @Override
    public void convert(ViewHolder holder, ReadLvInfo readShowAnswerInfo) {
        //题号A到E
        TextView tv_index = holder.getView(R.id.tv_index);

        //进度条
        ZzHorizontalProgressBar pb = holder.getView(R.id.pb);

        //正确率
        TextView tv_pb = holder.getView(R.id.tv_pb);

        //如果是正确的答案,则进度条颜色是绿色,如果是错误的答案,进度条是红色
        pb.setBgColor(context.getResources().getColor(R.color.tv_app_pb_bg));

        if (readShowAnswerInfo.questionIndex != null) {
            if (readShowAnswerInfo.questionIndex.equals(readShowAnswerInfo.rightAnswer)) {
                pb.setProgressColor(context.getResources().getColor(R.color.tv_app_pb_green));
                tv_pb.setTextColor(context.getResources().getColor(R.color.tv_app_pb_green));
            } else {
                pb.setProgressColor(context.getResources().getColor(R.color.tv_app_pb_red));
                tv_pb.setTextColor(context.getResources().getColor(R.color.tv_app_pb_red));
            }
        }

        tv_index.setText(readShowAnswerInfo.questionIndex);

        if (!TextUtils.isEmpty(readShowAnswerInfo.probability)) {
            //设置进度条的进度
            pb.setProgress((int) Double.parseDouble(readShowAnswerInfo.probability.substring
                    (0, readShowAnswerInfo.probability.length() - 1)));
            tv_pb.setText(readShowAnswerInfo.probability);
        } else {
            pb.setProgress(0);
            tv_pb.setText("0.0%");
        }
    }
}
